package com.nulldev.util.java.swing.extSwing.lookandfeel;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.SystemColor;
import java.util.ArrayList;

import javax.swing.JMenu;

import com.nulldev.util.java.swing.font.FontManager;
import com.nulldev.util.java.utils.color.ColorUtil;
import com.nulldev.util.other.ArrayUtils;

@Deprecated
/**
 * Replaced by ThemeAPI.
 * @author null
 *
 */
public class DFApplier {

	public static void applyDarkLookAndFeel(final Container c) {
		applyDarkLookAndFeel(c, false);
	}
	
	public static void applyDarkLookAndFeel(final Container c, final boolean skipTransparent) {
		FontManager.registerAll(c, true);
		final Font font = FontManager.getHighway(16);
		final ArrayList<Component> items = FontManager.getAllComponents(c);
		int its = 0;
		while (!items.isEmpty()) {
			for (final Component cx : (ArrayList<Component>) items.clone()) {
				if (cx instanceof JMenu) {
					try {
						items.addAll(ArrayUtils.toArrayList(((JMenu) cx).getMenuComponents()));
						if (cx.getBackground() != ColorUtil.TRANSPARENT && !skipTransparent) {
							cx.setBackground(Color.DARK_GRAY);
						}else if (cx.getBackground() == SystemColor.windowBorder) {
							cx.setForeground(Color.WHITE);
						}
						((JMenu) cx).setOpaque(true);
						
					}catch (Exception e) {
						e.printStackTrace();
						if (cx.getBackground() != ColorUtil.TRANSPARENT && !skipTransparent) {
							cx.setBackground(Color.DARK_GRAY);
						}else if (cx.getBackground() == SystemColor.windowBorder) {
							cx.setForeground(Color.WHITE);
						}
						cx.setForeground(Color.WHITE);
						((JMenu) cx).setOpaque(true);
					}
				}
				cx.setForeground(Color.WHITE);
				if (cx.getBackground() != ColorUtil.TRANSPARENT && !skipTransparent) {
					cx.setBackground(Color.DARK_GRAY);
				}
				cx.setFont(font);
				items.remove(0);
			}	
		}
	}
	
	public static void applyLightLookAndFeel(final Container c) {
		applyLightLookAndFeel(c, false);
	}
	
	public static void applyLightLookAndFeel(final Container c, final boolean skipTransparent) {
		FontManager.registerAll(c, true);
		final Font font = FontManager.getHighway(16);
		final ArrayList<Component> items = FontManager.getAllComponents(c);
		int its = 0;
		while (!items.isEmpty()) {
			for (final Component cx : (ArrayList<Component>) items.clone()) {
				if (cx instanceof JMenu) {
					try {
						items.addAll(ArrayUtils.toArrayList(((JMenu) cx).getMenuComponents()));
						if (cx.getBackground() != ColorUtil.TRANSPARENT && !skipTransparent) {
							cx.setBackground(Color.WHITE);
						}else if (cx.getBackground() == SystemColor.windowBorder) {
							cx.setForeground(Color.BLACK);
						}
						((JMenu) cx).setOpaque(true);
						
					}catch (Exception e) {
						e.printStackTrace();
						if (cx.getBackground() != ColorUtil.TRANSPARENT && !skipTransparent) {
							cx.setBackground(Color.WHITE);
						}else if (cx.getBackground() == SystemColor.windowBorder) {
							cx.setForeground(Color.BLACK);
						}
						cx.setForeground(Color.BLACK);
						((JMenu) cx).setOpaque(true);
					}
				}
				cx.setForeground(Color.BLACK);
				if (cx.getBackground() != ColorUtil.TRANSPARENT && !skipTransparent) {
					cx.setBackground(Color.WHITE);
				}
				cx.setFont(font);
				items.remove(0);
			}	
		}
	}
}
